<?php
ini_set('register_globals','on');
//require_once "config.inc.php";
$CURRENCY="$";

$SESSION_MIN = 10;
$current_year = date('Y');

function get_item($table_name,$where,$what,$getit) {
	$gq="SELECT * FROM `$table_name` WHERE `$where` = '$what' ";
	$gr=@mysql_query($gq);
	$tr=@mysql_fetch_array($gr);
	return $tr[$getit];
}

function get_allitem($table_name,$where,$what) {
	$gq="SELECT * FROM `$table_name` WHERE `$where` = '$what'";
	$gr=@mysql_query($gq);
	$tr=@mysql_fetch_array($gr);
	return $tr;
}
function cut_text($cut_it, $cut_on) {
if	(strlen(trim($cut_it))> $cut_on) {
echo substr($cut_it,0,$cut_on); 
echo "...";
} else {
echo "$cut_it";
}
}
function site_url(){
	$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; return $url; 	
}

/*
if(!isset($_SESSION['get_user_ip']))
{
get_user_ip();
}

//function for track ip
function get_user_ip()
{
$tt=time();
if(isset($_SERVER['HTTP_REFERER'])){ $http=$_SERVER['HTTP_REFERER'];
mysql_query("INSERT INTO track_ip SET back_link='".addslashes($http)."', ip_address='".addslashes($_SERVER['REMOTE_ADDR'])."', track_time='$tt' ") or die(mysql_error());
$_SESSION['get_user_ip']=1;
}
}*/

//function for page counter
function page_counter()
{
$get_count=mysql_fetch_array(mysql_query("SELECT visitor_no FROM global_setting WHERE id=1 "));
$get_count=$get_count[visitor_no];
$page_count=$get_count+1;
mysql_query("UPDATE global_setting SET visitor_no='$page_count' WHERE id=1 ") or die(mysql_error());
}

// function for admin login validation
function validate_admin()
{
	if(!isset($_SESSION['sess_admin_id']))
	header("Location:index.php?back=$_SERVER[REQUEST_URI]");
}
// function for admin login validation
function validate_user()
{
if(!isset($_SESSION['id']))
{
header("Location:index.php?back=$_SERVER[REQUEST_URI]");
exit;
}
}
// function for filter the string
function normal_filter($val)
{
return ucfirst(stripslashes($val));
}

function strip_filter($val, $size)
{
return substr(stripslashes(strip_tags($val)),0,$size);
}

function caps_filter($val)
{
return strtoupper(stripslashes($val));
}

function normalall_filter($val)
{
return ucwords(stripslashes($val));
}


// function for page handling
function get_qry_str($over_write_key = array(), $over_write_value= array())
{
	global $_GET;
	$m = $_GET;
	if(is_array($over_write_key)){
		$i=0;
		foreach($over_write_key as $key){
			$m[$key] = $over_write_value[$i];
			$i++;
		}
	}else{
		$m[$over_write_key] = $over_write_value;
	}
	$qry_str = qry_str($m);
	return $qry_str;
}

function qry_str($arr, $skip = '')
{
	$s = "?";
	$i = 0;
	foreach($arr as $key => $value) {
		if ($key != $skip) {
			if(is_array($value)){
				foreach($value as $value2){
					if ($i == 0) {
						$s .= "$key%5B%5D=$value2";
					$i = 1;
					} else {
						$s .= "&$key%5B%5D=$value2";
					}
				}
			}else{
				if ($i == 0) {
					$s .= "$key=$value";
					$i = 1;
				} else {
					$s .= "&$key=$value";
				}
			}
		}
	}
	return $s;
}

// function to include http
function format_url($url)
{
	if(!preg_match('/http:\/\//',$url))
	{
		$url="http://".$url;
	}
	return $url;
}



//////////////////////////////////////////////////////////////////////////////////////
// function to access description form content table
/////////////////////////////////////////////////////////////////////////////////
function show_descr($id)
{
	$row=mysql_fetch_array(mysql_query("select descr from content where id='$id'"));
	return $row['descr'];
}

function show_name($id)
{
	$row=mysql_fetch_array(mysql_query("select name from content where id='$id'"));
	return $row['name'];
}

// function to generate orderid
function generate_order_id()
{
	$param1=time();
	$param2=rand(1,1000);
	return $param1.$param2;
}
////////////////////////////////////////////////////////////////////////////////
// function to access description form content table
function enc($val){
if($val!='')
	{
	$new_val=base64_encode(base64_encode($val));
	return $new_val;
	}
}

function dec($val)
{
	if($val!='')
	{
		$org_val=base64_decode(base64_decode($val));
		return $org_val;
	}
}

function executeQuery($sql)
{
	$result = mysql_query($sql) or die("<span style='FONT-SIZE:11px; FONT-COLOR: #; font-family=tahoma;'><center>An Internal Error has Occured. Please report following error to the webmaster.<br><br>".$sql."<br><br>".mysql_error()."'</center></FONT>");
	return $result;
}
function dbText($val){
return trim(addslashes($val));
}

function frontText($val){
return stripslashes(ucfirst($val));
}

function oneupText($val){
return stripslashes(ucfirst($val));
}

function allupText($val,$sep=70){
return chunk_split(stripslashes(ucwords($val)),$sep);
}

function simpleText($val){
	$retarr = '';
	$arr = str_word_count($val, 2, ".\n1234567890~!@#$%&*()-_+=|\\[]{};:\'\"\?,`<>");
	foreach($arr as $k){
	$kk=strlen($k);
	if($kk>20) $retarr .= wordwrap($k,20,"<br />",true);
	else $retarr .= $k.' ';
	}
	return strip_tags(stripslashes($retarr));
}

function nlText($val){
	$retarr = '';
	$arr = str_word_count($val, 2, ".\n1234567890~!@#$%&*()-_+=|\\[]{};:\'\"\?,`<>");
	foreach($arr as $k){
	$kk=strlen($k);
	if($kk>20) $retarr .= wordwrap($k,20,"<br />",true);
	else $retarr .= $k.' ';
	}
	return nl2br(strip_tags(stripslashes(ucfirst($retarr))));
}
function date_dmy($date)
{
	if($date!='' && $date!='0000-00-00')
	{
	list($y,$m,$d)=explode("-",$date);
	return date("j M Y", mktime(0, 0, 0, $m, $d, $y));
	}
}

function dmy_date($date)
{
	if($date!='' && $date!='0000-00-00 00:00:00')
	{
	list($date,$time)=explode(" ",$date);
	list($y,$m,$d)=explode("-",$date);
	list($h,$min,$sec)=explode(":",$time);
	return date("D, j M Y g:i A", mktime($h, $min, $sec, $m, $d, $y));
	}
}
//to add content part
function add_content($id){
	$sql=mysql_query("SELECT * FROM `content` WHERE `id`='$id'");
	$row=mysql_fetch_array($sql);
	return $row;
}
//function for visiter counter///////////////////////////////////
function getImageCounter($count,$total_length=6)
{
$var=(string)$count;
if(strlen($var)>$total_length)
$total_length=strlen($var);
else
{
//print extra zeros
  for($i=0;$i<($total_length-strlen($var));$i++)
  {
    ?><img src="images/counter1/0.gif" style="padding-left:1px;" height="15" width="15" /><?php
  }
}
$total_length=strlen($var);
    for($i=0;$i<$total_length;$i++)
    {
    ?><img src="images/counter1/<?php echo $var[$i];?>.gif" style="padding-left:1px;" height="15" width="15" /><?php
    }

}
function visiter_today(){
	$today		=		time();
	$today_date	= 		strtotime(date("m/d/y",time()));
	$qry		=		mysql_query("SELECT * FROM `visit_counter` WHERE `visit_time` > $today_date");
	$num2		=		mysql_num_rows($qry);
	return $num2;
}
function visiter_yesterday(){
	$today				=		time();
	$today_date			= 		strtotime(date("m/d/y",time()));
	$yesterday_date		=		$today_date - 24*3600;
	$qry				=		mysql_query("SELECT * FROM `visit_counter` WHERE `visit_time` > $yesterday_date  && `visit_time` < $today_date");
	$num2				=		mysql_num_rows($qry);
	return $num2;
}
function x_week_range($date) {
    $ts 			=		($date);
    $start 			= 		(date('w', $ts) == 1) ? $ts : strtotime('last monday', $ts);
    return array(date('Y-m-d', $start),
                 date('Y-m-d', strtotime('next sunday', $start)));
}

function visiter_this_week(){
	$today			=	time();
	$range			=	x_week_range($today);
	$start			=	strtotime($range[0]);
	$end			=	strtotime($range[1]);
	$qry			=	mysql_query("SELECT * FROM `visit_counter` WHERE `visit_time` > '$start'  and `visit_time` < '$end'");
	$num2			=	mysql_num_rows($qry);
	return $num2;
}
function visiter_last_week(){
	$today	=	time();

	$week_seconds= 7*24*3600;
	$range	=	x_week_range($today);
	$start	=	strtotime($range[0])-$week_seconds;
	$end	=	strtotime($range[1])-$week_seconds;
	$qry	=	mysql_query("SELECT * FROM `visit_counter` WHERE `visit_time` > '$start'  and `visit_time` < '$end'");
	$num2	=	mysql_num_rows($qry);
	return $num2;
}
function visiter_this_month(){
	$today			=		time();
	list($m,$d,$y)	=		explode('/',date("m/d/Y"));
	$start			=		mktime(0,0,0,$m,1,$y);
	$end			=		mktime(0,0,0,$m+1,1,$y);
	$qry			=		mysql_query("SELECT * FROM `visit_counter` WHERE `visit_time` > '$start'  && `visit_time` < '$end'");
	$num2			=		mysql_num_rows($qry);
	return $num2;
}
function visiter_last_month(){
	$today			=		time();
	list($m,$d,$y)	=		explode('/',date("m/d/Y"));
	$start			=		mktime(0,0,0,$m-1,1,$y);
	$end			=		mktime(0,0,0,$m,1,$y);
	$qry			=		mysql_query("SELECT * FROM `visit_counter` WHERE `visit_time` > '$start'  && `visit_time` < '$end'");
	$num2			=		mysql_num_rows($qry);
	return $num2;
}
/////////////////////////////////////////////////////////////////
function get_course_list(){
	$sql=mysql_query("SELECT * FROM `courses`");
	while($row=mysql_fetch_array($sql)){
	echo "<li><a href='courses.php?id=$row[id]'>$row[name]</a></li>";
	}
}
function add_service_content($id){
	$sql1=mysql_query("SELECT * FROM `courses` WHERE id = $id");
	$row1=mysql_fetch_array($sql1);
	return $row1;
}

function have_sub_cat($id){

	$sql1=mysql_query("SELECT * FROM `page` WHERE parent_id ='$id' && status=1")or die(mysql_error()) ;
	$num=mysql_num_rows($sql1);
	if ($num !== 0){
			//$sql1=mysql_query("SELECT * FROM `service` WHERE parent_id = $id");
			echo "";
			while($row1=mysql_fetch_array($sql1)){
			echo "<li><a href='page.php?id=$row1[id]'>$row1[name]</a></li>";
			}
			echo "";	
		}
}
function get_cat(){
	$sql=mysql_query("SELECT * FROM `page` WHERE parent_id=0 and status=1") or die(mysql_error());
	while($row=mysql_fetch_array($sql)){
	if(isset($_REQUEST['id']) && ($_REQUEST['id']==$row['id']))
	$class="active";
	else
	$class="";
	
	  if(mysql_num_rows(mysql_query("SELECT id FROM `page` WHERE parent_id='".$row['id']."' and status=1 ")))
	  {
	  	echo "<li class='top'><a href='page.php?id=$row[id]' class='top_link ".$class."'><span class='down'>$row[name]</span></a>";
		have_sub_cat($row['id']);
		echo "</li>";

	  }
	  else
	  {
	  	echo "<li class='top'><a href='page.php?id=$row[id]' class='top_link ".$class."'><span>$row[name]</span></a></li>";

	  }
	}
}
function get_foot_cat(){
	$sql=mysql_query("SELECT * FROM `page` WHERE parent_id=0 and status=1") or die(mysql_error());
	while($row=mysql_fetch_array($sql)){
	 echo "<li><a href='page.php?id=$row[id]'>$row[name]</a> </li>";
	}
}
function add_page_content($id){
	$sql1=mysql_query("SELECT * FROM `page` WHERE id = $id");
	$row1=mysql_fetch_array($sql1);
	return $row1;
}
function get_reg_category($id){
	$sql=mysql_query("SELECT * FROM `content` WHERE id= $id && status=1");
	while($row=mysql_fetch_array($sql)){
	echo "$row[name]";
	}
}
function get_reg_cat(){
	$sql=mysql_query("SELECT * FROM `page`");
	while($row=mysql_fetch_array($sql)){
	echo "<option value='$row[id]'>$row[name]</option>";
	}
}
//for courses
function add_courses_content($id){
	$sql=mysql_query("SELECT * FROM `courses` WHERE id = $id");
	$row9=mysql_fetch_array($sql);
	return $row9;
}
function add_courses_list(){
	$sql=mysql_query("SELECT * FROM `courses` WHERE parent_id=0 ORDER BY id");
	$num=mysql_num_rows($sql);
	if ($num !== 0){
			//$sql1=mysql_query("SELECT * FROM `service` WHERE parent_id = $id");
			echo "<ul>";
			while($row1=mysql_fetch_array($sql)){ $b=substr($row1['name'],0,17); if(substr($row1['name'],19,25)!="") $b.="...";
			echo "<li><a href='courses.php?id=$row1[id]' title='".stripslashes($row1['name'])."'>$b</a></li>";
			}
			echo "</ul>";	
		}
}
function get_courses_cat(){
	$sql=mysql_query("SELECT * FROM `courses` WHERE parent_id=0");
	while($row=mysql_fetch_array($sql)){
	echo "<option value='$row[id]'>$row[name]</option>";
	}
}
function get_courses_name($id){
	$sql=mysql_query("SELECT * FROM `courses` WHERE id=$id");
	$row=mysql_fetch_array($sql);
	return $row;
}
function get_courses_cat_name($id){
	$sql=mysql_query("SELECT * FROM `courses` WHERE `id`='$id'");
	$row=mysql_fetch_array($sql);
	return $row;
}
///Get Header
function get_header($id){
	$sql=mysql_query("SELECT * FROM `courses` WHERE `id`=$id && `status`=1 ");
	$row=mysql_fetch_array($sql);
	return $row;
}
function get_image($id){
	$sql=mysql_query("SELECT * FROM `banner` WHERE `parent_id`=$id && `status`=1 ");
	$row=mysql_fetch_array($sql);
	return $row;
}
//////////////////////
function get_lcd_image($id){
	?> 
<?php
	echo '<script language="javascript">';
	echo 'var fadeimages=new Array();';
	$q=mysql_query("SELECT * FROM header_img WHERE parent_id=$id && status=1");
	$i = 0;
	while($row=mysql_fetch_array($q))
	{
		echo 'fadeimages['.$i.']=["admin/banner/ori/'.$row['image'].'", "", ""];';
		$i++;
	}
	echo '</script>';
?>

	<script type="text/javascript">
		//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
		new fadeshow(fadeimages, 466, 262, 0, 1000, 1, "R")
		</script>
<?php	
}
function add_demo_txt(){
	$sql=mysql_query("SELECT * FROM `demo_content` ");
	$row=mysql_fetch_array($sql);
	return $row;	
}
function get_user($id){
	$sql=mysql_query("SELECT * FROM `online_admission` WHERE id='$id'");
	$row=mysql_fetch_array($sql);
	return $row;
}
function get_staff($id){
	$sql=mysql_query("SELECT * FROM `staff` WHERE id='$id'");
	$row=mysql_fetch_array($sql);
	return $row;
}
function get_sub_course($id){
	$sql=mysql_query("SELECT * FROM `courses` WHERE parent_id=$id");
	while($row=mysql_fetch_array($sql)){
	echo $row['name'].",&nbsp; ";
	}	
}
function branch_name($id){
	$sql1=mysql_query("SELECT * FROM `page` WHERE id='".$id."' && parent_id=9 && status=1")or die(mysql_error()) ;
			$row1=mysql_fetch_array($sql1);
			echo $row1['name'];
}

function branch_name_from_staff_id($id){

	$sql1=mysql_query("SELECT * FROM `staff` WHERE id='".$id."' and status=1")or die(mysql_error()) ;
			$row1=mysql_fetch_array($sql1);
			$id = $row1['branch'];
	
	$sql1=mysql_query("SELECT * FROM `page` WHERE id='".$id."' && parent_id=9 && status=1")or die(mysql_error()) ;
			$row1=mysql_fetch_array($sql1);
			return $row1['name'];
}

function student_profile_link_using_id($id){
	$sql1=mysql_query("SELECT * FROM `online_admission` WHERE id='".$id."' && status=1")or die(mysql_error()) ;
			$row1=mysql_fetch_array($sql1);
			$studentId=$row1['id'];
			echo "<a href='details.php?id=$studentId'>".stripslashes(ucfirst($row1['name'])) ."</a>";
}
function manage_nav($id){
    $sql=mysql_query("select * from `nav` where `id`='$id'")or die(mysql_error());
    $row=mysql_fetch_array($sql);
    echo $row['name'];
}

?>